package com.aidex.biz.controller;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.BizAssessInfo;
import com.aidex.biz.service.BizAssessInfoService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 考核信息Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-11-29
 */
@RestController
@RequestMapping("/biz/bizAssessInfo")
public class BizAssessInfoController extends BaseController
{
    @Autowired
    private BizAssessInfoService bizAssessInfoService;

    /**
     * 查询考核信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizAssessInfo bizAssessInfo, HttpServletRequest request, HttpServletResponse response)
    {

        bizAssessInfo.setPage(new PageDomain(request, response));
        return R.data(bizAssessInfoService.findPage(bizAssessInfo));
    }



    /**
     * 获取考核信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:query')")
    @GetMapping(value = "/{id}")
    public R<BizAssessInfo> detail(@PathVariable("id") String id)
    {
        return R.data(bizAssessInfoService.get(id));
    }

    /**
     * 新增考核信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:add')")
    @Log(title = "考核信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizAssessInfo bizAssessInfo)
    {

        bizAssessInfo.setIsNewRecord();
        bizAssessInfo.setTotal(bizAssessInfo.getDeptIds().length);
        return R.status(bizAssessInfoService.save(bizAssessInfo));
    }

    /**
     * 修改考核信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:edit')")
    @Log(title = "考核信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizAssessInfo bizAssessInfo)
    {
        bizAssessInfo.setTotal(bizAssessInfo.getDeptIds().length);
        return R.status(bizAssessInfoService.save(bizAssessInfo));
    }

//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:edit')")
    @Log(title = "考核信息", businessType = BusinessType.UPDATE)
    @PostMapping("/fabu")
    public R fabu(@RequestBody @Validated BizAssessInfo bizAssessInfo)
    {
        BizAssessInfo bizAssessInfo_old=bizAssessInfoService.get(bizAssessInfo.getId());
        bizAssessInfo_old.setStatus(bizAssessInfo.getStatus());
        bizAssessInfo_old.setFabuTime(new Date());
        return bizAssessInfoService.fabu(bizAssessInfo_old)?R.success():R.fail("请添加考核内容，再发布");
    }


    /**
     * 删除考核信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:remove')")
    @Log(title = "考核信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(bizAssessInfoService.deleteBizAssessInfoByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(bizAssessInfoService.findMaxSort(new BizAssessInfo()));
    }

    /**
     * 导出考核信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizAssessInfo:export')")
    @Log(title = "考核信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizAssessInfo bizAssessInfo)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    bizAssessInfo.setCompanyId(null);
            }else{
                         bizAssessInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<BizAssessInfo> list = bizAssessInfoService.findList(bizAssessInfo);
        ExcelUtil<BizAssessInfo> util = new ExcelUtil<BizAssessInfo>(BizAssessInfo.class);
        return util.exportExcel(list, "考核信息数据");
    }


    @GetMapping("/getId")
    public R getId(BizAssessInfo bizAssessInfo)
    {

        return R.data(UUID.randomUUID().toString());
    }





}
